using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace SPTraceView.Model
{
    /// <summary>
    /// For more info see http://msdn.microsoft.com/hi-in/library/aa979595(en-us).aspx
    /// </summary>
    internal static class ULS
    {
        public static string WSS_TRACE_SESSION_NAME = "WSSTRACESESSION14";

        public static Guid WSSProviderGuid
        {
            get
            {
               
                // Taken from Microsoft.SharePoint.Administration.SPFarm.TraceSessionGuid
                // To avoid referencing any SharePoint DLLs
                //SP2007 Trace Session GUID 
                //return new Guid(0x89c8c935, 0x99ff, 0x48ce, 0x93, 0x76, 0x31, 0xda, 170, 0xf3, 0x2b, 0x85);
                
                //SP2010 Trace Session GUID
                return new Guid(0x5d3dd95, 0x2b48, 0x4791, 0xbc, 0xe5, 0xc9, 0xb6, 0x4b, 160, 0x44, 0x71);

            }
        }

         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        internal struct ULSTraceHeader1
        {
            internal ushort Size;

            internal uint Version;

            //[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
            //internal byte[] b;
            internal uint i1,i2,i3,i4;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
            internal string ExeName;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
            internal string Product;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
            internal string Category;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 800)]
            internal string Message;

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 112)]
            internal byte[] b1;

            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            internal string Message1;


        }

         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
         internal struct ULSTraceHeader_SP2007
         {
             internal ushort Size;
             internal uint Version;
             internal uint Id;
             internal Guid correlationID;
             internal TraceFlags Flags;
             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
             internal string wzExeName;
             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
             internal string wzProduct;
             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
             internal string wzCategory;
             [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 800)]
             internal string wzMessage;
         }



         //http://msdn.microsoft.com/en-us/library/aa979522.aspx

        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
        internal struct ULSTraceHeader
        {
            public ushort Size;
            public uint Version;
            public uint Id;
            public TraceFlags Flags;
            public long TimeStamp;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string ExeName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string Product;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string Category;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 801)]
            public string Message;
        }

        [Flags]
        internal enum TraceFlags
        {
            None = 0,
            TRACE_FLAG_START = 1,
            TRACE_FLAG_END = 2,
            TRACE_FLAG_MIDDLE = 3, // Notice middle==start+end, allows use as a bitmask.
            TRACE_FLAG_ID_AS_ASCII = 4,
             TRACE_FLAG_UNKNOWN_5 = 5, //start + ID AS ASCII
            TRACE_FLAG_UNKNOWN_6 = 6, //END + ID AS ASCII
            TRACE_FLAG_FLUSH = 8, // Ask trace manager to flush all file buffers.
        }



        public enum TraceSeverity //: byte
        {
             Unassigned=0,
            CriticalEvent = 1,
            Exception = 4,
            Assert = 7,
            WarningEvent = 8,
            Unexpected = 10,
            Monitorable = 15,
            InformationEvent = 18,
            High = 20,
            Medium = 50,
            Verbose = 100,
            VerboseEx = 200,
           
        }
 

    }
}
